<script setup>
import { ref } from 'vue'

const moodEntries = ref([
  {
    id: 1,
    date: '2024-03-20',
    mood: 'happy',
    intensity: 85,
    title: '阳光明媚的一天',
    content: '今天完成了一个重要项目，心情特别愉快！',
    tags: ['工作', '成就感'],
    artStyle: 'watercolor',
    generatedArt: 'https://placekitten.com/300/200'
  },
  {
    id: 2,
    date: '2024-03-19',
    mood: 'calm',
    intensity: 70,
    title: '宁静午后',
    content: '在咖啡馆度过了一个平静的下午，看书写字。',
    tags: ['放松', '咖啡'],
    artStyle: 'minimalist',
    generatedArt: 'https://placekitten.com/301/200'
  }
])

const moodTypes = {
  happy: { icon: '😊', color: 'var(--mood-happy)', label: '开心' },
  calm: { icon: '😌', color: 'var(--mood-calm)', label: '平静' },
  sad: { icon: '😢', color: 'var(--mood-sad)', label: '难过' },
  angry: { icon: '😠', color: 'var(--mood-angry)', label: '生气' }
}

const showNewEntry = ref(false)
const newEntry = ref({
  mood: 'happy',
  intensity: 50,
  title: '',
  content: '',
  tags: []
})

const toggleNewEntry = () => {
  showNewEntry.value = !showNewEntry.value
}

const addEntry = () => {
  // 这里添加新日记的逻辑
  showNewEntry.value = false
}
</script>

<template>
  <div class="mood-journal">
    <!-- 顶部操作栏 -->
    <div class="journal-header">
      <h1 class="section-title">心情日记</h1>
      <button class="mood-btn" @click="toggleNewEntry">
        <span>✍️</span>
        记录此刻心情
      </button>
    </div>

    <!-- 新建日记表单 -->
    <div v-if="showNewEntry" class="new-entry-form mood-card">
      <div class="mood-selector">
        <button 
          v-for="(type, key) in moodTypes"
          :key="key"
          :class="['mood-btn', 'mood-type-btn', newEntry.mood === key ? 'active' : '']"
          :style="{ '--mood-color': type.color }"
          @click="newEntry.mood = key"
        >
          <span class="mood-icon">{{ type.icon }}</span>
          {{ type.label }}
        </button>
      </div>

      <div class="mood-intensity">
        <label>心情强度</label>
        <input 
          v-model="newEntry.intensity"
          type="range"
          min="0"
          max="100"
          class="intensity-slider"
        >
        <span class="intensity-value">{{ newEntry.intensity }}%</span>
      </div>

      <div class="form-group">
        <input 
          v-model="newEntry.title"
          type="text"
          class="mood-input"
          placeholder="给这一刻起个标题..."
        >
      </div>

      <div class="form-group">
        <textarea 
          v-model="newEntry.content"
          class="mood-input"
          rows="4"
          placeholder="写下你的心情..."
        ></textarea>
      </div>

      <div class="form-actions">
        <button class="mood-btn" @click="addEntry">
          <span>✨</span>
          生成艺术并保存
        </button>
        <button class="mood-btn secondary" @click="showNewEntry = false">
          取消
        </button>
      </div>
    </div>

    <!-- 日记列表 -->
    <div class="entries-grid">
      <div 
        v-for="entry in moodEntries"
        :key="entry.id"
        class="mood-card entry-card"
      >
        <div class="entry-header">
          <div class="mood-indicator" :style="{ background: moodTypes[entry.mood].color }">
            <span class="mood-icon">{{ moodTypes[entry.mood].icon }}</span>
            <span class="mood-intensity">{{ entry.intensity }}%</span>
          </div>
          <div class="entry-date">{{ entry.date }}</div>
        </div>

        <h3 class="entry-title">{{ entry.title }}</h3>
        <p class="entry-content">{{ entry.content }}</p>

        <div class="entry-tags">
          <span 
            v-for="(tag, index) in entry.tags"
            :key="index"
            class="mood-tag"
          >
            {{ tag }}
          </span>
        </div>

        <div class="generated-art">
          <img :src="entry.generatedArt" :alt="entry.title">
          <div class="art-overlay">
            <span class="art-style">{{ entry.artStyle }}</span>
          </div>
        </div>

        <div class="entry-actions">
          <button class="mood-btn icon-btn">
            <span>🖼️</span>
          </button>
          <button class="mood-btn icon-btn">
            <span>✏️</span>
          </button>
          <button class="mood-btn icon-btn">
            <span>🗑️</span>
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.mood-journal {
  padding: 1rem;
}

.journal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.new-entry-form {
  margin-bottom: 2rem;
}

.mood-selector {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.mood-type-btn {
  background: var(--mood-color);
  flex: 1;
  justify-content: center;
  min-width: 120px;
}

.mood-type-btn.active {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.mood-icon {
  font-size: 1.5rem;
}

.mood-intensity {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.intensity-slider {
  flex: 1;
  height: 8px;
  -webkit-appearance: none;
  background: #e2e8f0;
  border-radius: 4px;
}

.intensity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: var(--primary-color);
  border-radius: 50%;
  cursor: pointer;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-actions {
  display: flex;
  gap: 1rem;
}

.secondary {
  background: var(--text-secondary);
}

.entries-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 2rem;
}

.entry-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mood-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  color: white;
}

.entry-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
}

.entry-content {
  color: var(--text-secondary);
  line-height: 1.6;
}

.entry-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.generated-art {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
}

.generated-art img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.art-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  font-size: 0.9rem;
}

.entry-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.icon-btn {
  padding: 0.5rem;
  border-radius: 8px;
}

@keyframes slideIn {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.new-entry-form {
  animation: slideIn 0.3s ease-out;
}
</style> 